﻿namespace PMS.Client.FrmUserRegist
{
    using PMS.BLL;
    using PMS.Client.FrmOrgan;
    using PMS.Client.FrmUserBuild;
    using PMS.Common;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FrmUpdateRegist : Form
    {
        private Button btnCancel;
        private Button btnGetOrgan;
        private Button btnSave;
        private Button btnUserBuild;
        private IContainer components = null;
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private CheckBox IsHighWith;
        private Label label1;
        private Label label17;
        private Label label18;
        private Label label19;
        private Label label20;
        private Label label21;
        private Label label23;
        private Label label24;
        private Label label25;
        private Label label40;
        private Label label45;
        private Label label8;
        private Label lbTitle;
        private UserChangeLog log = null;
        private UserChangeLogBLL logbll = new UserChangeLogBLL();
        private User model = null;
        private DateTimePicker RegistDate;
        private DateTimePicker RegistDay;
        private TextBox RegistFrom;
        private TextBox RegistNo;
        private ComboBox RegistState;
        private TextBox RegistSummary;
        private TextBox RegistTo;
        private TextBox RegistType;
        private ComboBox RegistWay;
        private TextBox txtID;
        private UserBLL userbll = new UserBLL();
        private int userID = 0;
        private TextBox UserName;

        public FrmUpdateRegist(int userID)
        {
            this.userID = userID;
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnGetOrgan_Click(object sender, EventArgs e)
        {
            PMS.Client.FrmOrgan.FrmSelect select = new PMS.Client.FrmOrgan.FrmSelect();
            select.ShowDialog();
            if (select.DialogResult == DialogResult.OK)
            {
                this.RegistTo.Text = select.OrganName;
                this.RegistTo.Tag = select.Organ;
            }
        }

        private void btnRegistTo_Click(object sender, EventArgs e)
        {
            PMS.Client.FrmOrgan.FrmSelect select = new PMS.Client.FrmOrgan.FrmSelect();
            select.ShowDialog();
            if (select.DialogResult == DialogResult.OK)
            {
                this.RegistTo.Text = select.OrganName;
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.log = new UserChangeLog();
            this.log.UserID = this.userID;
            this.log.RegistFrom = (this.model.RegistFrom == this.RegistFrom.Text) ? null : this.RegistFrom.Text;
            if (this.model.RegistDate != this.RegistDay.Value)
            {
                this.log.RegistDate = new DateTime?(this.RegistDay.Value);
            }
            this.log.RegistState = (this.model.RegistState == this.RegistState.Text) ? null : this.RegistState.Text;
            this.log.RegistWay = (this.model.RegistWay == this.RegistWay.Text) ? null : this.RegistWay.Text;
            this.log.RegistTo = (this.model.RegistTo == this.RegistTo.Text) ? null : this.RegistTo.Text;
            this.log.RegistType = (this.model.RegistType == this.RegistType.Text) ? null : this.RegistType.Text;
            int? isHeighWith = this.model.IsHeighWith;
            int num = this.IsHighWith.Checked ? 1 : 0;
            if ((isHeighWith.GetValueOrDefault() != num) || !isHeighWith.HasValue)
            {
                this.log.IsHeighWith = new int?(this.IsHighWith.Checked ? 1 : 0);
            }
            this.log.IsOfficer = new int?(((Organ) this.RegistTo.Tag).IsOffice);
            this.log.OrganID = new int?(((Organ) this.RegistTo.Tag).OrganID);
            this.log.RegistNo = (this.model.RegistNo == this.RegistNo.Text) ? null : this.RegistNo.Text;
            this.log.RegistSummary = (this.model.RegistSummary == this.RegistSummary.Text) ? null : this.RegistSummary.Text;
            if (this.model.RegistDay != this.RegistDate.Value)
            {
                this.log.RegistDay = new DateTime?(this.RegistDate.Value);
            }
            this.log.CheckState = "未审核";
            this.log.LogType = "入编";
            this.log.UpdateDate = new DateTime?(DateTime.Now);
            this.log.UpdateUser = PMS.Common.Keys.Admin.LoginName;
            try
            {
                if (this.logbll.Add(this.log) > 0)
                {
                    MessageBox.Show("修改成功，等待审核中！");
                    base.DialogResult = DialogResult.OK;
                    base.Close();
                }
                else
                {
                    MessageBox.Show("修改失败！");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("修改失败！错误：" + exception.Message);
            }
        }

        private void btnUserBuild_Click(object sender, EventArgs e)
        {
            PMS.Client.FrmUserBuild.FrmSelect select = new PMS.Client.FrmUserBuild.FrmSelect();
            select.ShowDialog();
            if (select.DialogResult == DialogResult.OK)
            {
                this.RegistType.Text = select.UserBuildName;
            }
        }

        private void btnUserType_Click(object sender, EventArgs e)
        {
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmUpdateBaseInfo_Load(object sender, EventArgs e)
        {
            this.UserRegistWayBind();
            this.UserRegistStateBind();
            this.UserInfoBind();
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmUpdateRegist));
            this.groupBox2 = new GroupBox();
            this.btnGetOrgan = new Button();
            this.RegistDate = new DateTimePicker();
            this.label45 = new Label();
            this.RegistState = new ComboBox();
            this.label40 = new Label();
            this.btnUserBuild = new Button();
            this.RegistWay = new ComboBox();
            this.RegistSummary = new TextBox();
            this.label25 = new Label();
            this.RegistNo = new TextBox();
            this.label24 = new Label();
            this.IsHighWith = new CheckBox();
            this.label23 = new Label();
            this.RegistType = new TextBox();
            this.label21 = new Label();
            this.RegistDay = new DateTimePicker();
            this.label20 = new Label();
            this.label19 = new Label();
            this.RegistTo = new TextBox();
            this.label18 = new Label();
            this.RegistFrom = new TextBox();
            this.label17 = new Label();
            this.btnCancel = new Button();
            this.btnSave = new Button();
            this.lbTitle = new Label();
            this.groupBox1 = new GroupBox();
            this.txtID = new TextBox();
            this.label1 = new Label();
            this.UserName = new TextBox();
            this.label8 = new Label();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            base.SuspendLayout();
            this.groupBox2.Controls.Add(this.btnGetOrgan);
            this.groupBox2.Controls.Add(this.RegistDate);
            this.groupBox2.Controls.Add(this.label45);
            this.groupBox2.Controls.Add(this.RegistState);
            this.groupBox2.Controls.Add(this.label40);
            this.groupBox2.Controls.Add(this.btnUserBuild);
            this.groupBox2.Controls.Add(this.RegistWay);
            this.groupBox2.Controls.Add(this.RegistSummary);
            this.groupBox2.Controls.Add(this.label25);
            this.groupBox2.Controls.Add(this.RegistNo);
            this.groupBox2.Controls.Add(this.label24);
            this.groupBox2.Controls.Add(this.IsHighWith);
            this.groupBox2.Controls.Add(this.label23);
            this.groupBox2.Controls.Add(this.RegistType);
            this.groupBox2.Controls.Add(this.label21);
            this.groupBox2.Controls.Add(this.RegistDay);
            this.groupBox2.Controls.Add(this.label20);
            this.groupBox2.Controls.Add(this.label19);
            this.groupBox2.Controls.Add(this.RegistTo);
            this.groupBox2.Controls.Add(this.label18);
            this.groupBox2.Controls.Add(this.RegistFrom);
            this.groupBox2.Controls.Add(this.label17);
            this.groupBox2.Location = new Point(12, 0x65);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x2c9, 0xcc);
            this.groupBox2.TabIndex = 3;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "编制信息";
            this.btnGetOrgan.BackColor = Color.Gainsboro;
            this.btnGetOrgan.FlatAppearance.BorderColor = Color.DimGray;
            this.btnGetOrgan.FlatStyle = FlatStyle.Flat;
            this.btnGetOrgan.Location = new Point(0xbd, 0x47);
            this.btnGetOrgan.Name = "btnGetOrgan";
            this.btnGetOrgan.Size = new Size(0x15, 0x15);
            this.btnGetOrgan.TabIndex = 0x4f;
            this.btnGetOrgan.Text = "…";
            this.btnGetOrgan.UseVisualStyleBackColor = false;
            this.btnGetOrgan.Click += new EventHandler(this.btnGetOrgan_Click);
            this.RegistDate.CalendarMonthBackground = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistDate.Location = new Point(0x141, 0x98);
            this.RegistDate.Name = "RegistDate";
            this.RegistDate.Size = new Size(0x87, 0x15);
            this.RegistDate.TabIndex = 0x4e;
            this.label45.AutoSize = true;
            this.label45.Location = new Point(0x106, 0x9c);
            this.label45.Name = "label45";
            this.label45.Size = new Size(0x35, 12);
            this.label45.TabIndex = 0x4d;
            this.label45.Text = "下文时间";
            this.RegistState.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistState.DropDownStyle = ComboBoxStyle.DropDownList;
            this.RegistState.FlatStyle = FlatStyle.Flat;
            this.RegistState.FormattingEnabled = true;
            this.RegistState.ItemHeight = 12;
            this.RegistState.Items.AddRange(new object[] { "请选择" });
            this.RegistState.Location = new Point(0x227, 70);
            this.RegistState.Name = "RegistState";
            this.RegistState.Size = new Size(0x87, 20);
            this.RegistState.TabIndex = 0x2a;
            this.label40.AutoSize = true;
            this.label40.Location = new Point(0x1ec, 0x4b);
            this.label40.Name = "label40";
            this.label40.Size = new Size(0x35, 12);
            this.label40.TabIndex = 0x36;
            this.label40.Text = "在编状态";
            this.btnUserBuild.BackColor = Color.Gainsboro;
            this.btnUserBuild.FlatAppearance.BorderColor = Color.DimGray;
            this.btnUserBuild.FlatStyle = FlatStyle.Flat;
            this.btnUserBuild.Location = new Point(0x1b3, 0x47);
            this.btnUserBuild.Name = "btnUserBuild";
            this.btnUserBuild.Size = new Size(0x15, 0x15);
            this.btnUserBuild.TabIndex = 0x35;
            this.btnUserBuild.Text = "…";
            this.btnUserBuild.UseVisualStyleBackColor = false;
            this.btnUserBuild.Click += new EventHandler(this.btnUserBuild_Click);
            this.RegistWay.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistWay.DropDownStyle = ComboBoxStyle.DropDownList;
            this.RegistWay.FlatStyle = FlatStyle.Flat;
            this.RegistWay.FormattingEnabled = true;
            this.RegistWay.ItemHeight = 12;
            this.RegistWay.Items.AddRange(new object[] { "请选择" });
            this.RegistWay.Location = new Point(0x227, 0x21);
            this.RegistWay.Name = "RegistWay";
            this.RegistWay.Size = new Size(0x87, 20);
            this.RegistWay.TabIndex = 0x34;
            this.RegistSummary.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistSummary.BorderStyle = BorderStyle.FixedSingle;
            this.RegistSummary.Location = new Point(0x227, 0x98);
            this.RegistSummary.Name = "RegistSummary";
            this.RegistSummary.Size = new Size(0x87, 0x15);
            this.RegistSummary.TabIndex = 0x2f;
            this.label25.AutoSize = true;
            this.label25.Location = new Point(0x204, 0x9c);
            this.label25.Name = "label25";
            this.label25.Size = new Size(0x1d, 12);
            this.label25.TabIndex = 0x2e;
            this.label25.Text = "摘要";
            this.RegistNo.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistNo.BorderStyle = BorderStyle.FixedSingle;
            this.RegistNo.Location = new Point(0x4b, 0x98);
            this.RegistNo.Name = "RegistNo";
            this.RegistNo.Size = new Size(0x87, 0x15);
            this.RegistNo.TabIndex = 0x2d;
            this.label24.AutoSize = true;
            this.label24.Location = new Point(0x10, 0x9c);
            this.label24.Name = "label24";
            this.label24.Size = new Size(0x35, 12);
            this.label24.TabIndex = 0x2c;
            this.label24.Text = "控编文号";
            this.IsHighWith.AutoSize = true;
            this.IsHighWith.Location = new Point(0x4b, 0x73);
            this.IsHighWith.Name = "IsHighWith";
            this.IsHighWith.Size = new Size(15, 14);
            this.IsHighWith.TabIndex = 0x2b;
            this.IsHighWith.UseVisualStyleBackColor = true;
            this.label23.AutoSize = true;
            this.label23.Location = new Point(0x10, 0x74);
            this.label23.Name = "label23";
            this.label23.Size = new Size(0x35, 12);
            this.label23.TabIndex = 0x37;
            this.label23.Text = "是否高配";
            this.RegistType.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistType.BorderStyle = BorderStyle.FixedSingle;
            this.RegistType.Location = new Point(0x141, 0x47);
            this.RegistType.Name = "RegistType";
            this.RegistType.ReadOnly = true;
            this.RegistType.Size = new Size(0x87, 0x15);
            this.RegistType.TabIndex = 0x27;
            this.label21.AutoSize = true;
            this.label21.Location = new Point(0x106, 0x4b);
            this.label21.Name = "label21";
            this.label21.Size = new Size(0x35, 12);
            this.label21.TabIndex = 0x26;
            this.label21.Text = "编制类型";
            this.RegistDay.CalendarMonthBackground = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistDay.Location = new Point(0x141, 0x22);
            this.RegistDay.Name = "RegistDay";
            this.RegistDay.Size = new Size(0x87, 0x15);
            this.RegistDay.TabIndex = 0x25;
            this.label20.AutoSize = true;
            this.label20.Location = new Point(0xee, 0x26);
            this.label20.Name = "label20";
            this.label20.Size = new Size(0x4d, 12);
            this.label20.TabIndex = 0x11;
            this.label20.Text = "入编登记时间";
            this.label19.AutoSize = true;
            this.label19.Location = new Point(0x1ec, 0x26);
            this.label19.Name = "label19";
            this.label19.Size = new Size(0x35, 12);
            this.label19.TabIndex = 15;
            this.label19.Text = "入编形式";
            this.RegistTo.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistTo.BorderStyle = BorderStyle.FixedSingle;
            this.RegistTo.Location = new Point(0x4b, 0x47);
            this.RegistTo.Name = "RegistTo";
            this.RegistTo.ReadOnly = true;
            this.RegistTo.Size = new Size(0x87, 0x15);
            this.RegistTo.TabIndex = 14;
            this.label18.AutoSize = true;
            this.label18.Location = new Point(0x10, 0x49);
            this.label18.Name = "label18";
            this.label18.Size = new Size(0x35, 12);
            this.label18.TabIndex = 13;
            this.label18.Text = "现编单位";
            this.RegistFrom.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.RegistFrom.BorderStyle = BorderStyle.FixedSingle;
            this.RegistFrom.Location = new Point(0x4b, 0x22);
            this.RegistFrom.Name = "RegistFrom";
            this.RegistFrom.Size = new Size(0x87, 0x15);
            this.RegistFrom.TabIndex = 12;
            this.label17.AutoSize = true;
            this.label17.Location = new Point(0x10, 0x26);
            this.label17.Name = "label17";
            this.label17.Size = new Size(0x35, 12);
            this.label17.TabIndex = 0;
            this.label17.Text = "入编来源";
            this.btnCancel.BackColor = Color.White;
            this.btnCancel.FlatStyle = FlatStyle.Popup;
            this.btnCancel.Location = new Point(0x1a0, 0x146);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 9;
            this.btnCancel.Text = "关闭";
            this.btnCancel.UseVisualStyleBackColor = false;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnSave.BackColor = Color.White;
            this.btnSave.FlatStyle = FlatStyle.Popup;
            this.btnSave.Location = new Point(0xf8, 0x146);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new Size(0x4b, 0x17);
            this.btnSave.TabIndex = 8;
            this.btnSave.Text = "保存";
            this.btnSave.UseVisualStyleBackColor = false;
            this.btnSave.Click += new EventHandler(this.btnSave_Click);
            this.lbTitle.BackColor = Color.Gold;
            this.lbTitle.Dock = DockStyle.Top;
            this.lbTitle.Font = new Font("宋体", 14.25f, FontStyle.Bold, GraphicsUnit.Point, 0x86);
            this.lbTitle.ForeColor = Color.Black;
            this.lbTitle.Location = new Point(0, 0);
            this.lbTitle.Name = "lbTitle";
            this.lbTitle.Size = new Size(0x2e1, 0x1f);
            this.lbTitle.TabIndex = 11;
            this.lbTitle.Text = "更新人员编制信息";
            this.lbTitle.TextAlign = ContentAlignment.MiddleCenter;
            this.groupBox1.Controls.Add(this.txtID);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.UserName);
            this.groupBox1.Controls.Add(this.label8);
            this.groupBox1.ForeColor = SystemColors.WindowText;
            this.groupBox1.Location = new Point(15, 0x22);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(710, 0x35);
            this.groupBox1.TabIndex = 12;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "基本信息";
            this.txtID.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.txtID.BorderStyle = BorderStyle.FixedSingle;
            this.txtID.Location = new Point(0x13e, 0x13);
            this.txtID.Name = "txtID";
            this.txtID.ReadOnly = true;
            this.txtID.Size = new Size(0x87, 0x15);
            this.txtID.TabIndex = 13;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0x103, 0x17);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x35, 12);
            this.label1.TabIndex = 12;
            this.label1.Text = "身份证号";
            this.UserName.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.UserName.BorderStyle = BorderStyle.FixedSingle;
            this.UserName.Location = new Point(0x4a, 0x13);
            this.UserName.Name = "UserName";
            this.UserName.ReadOnly = true;
            this.UserName.Size = new Size(0x87, 0x15);
            this.UserName.TabIndex = 11;
            this.label8.AutoSize = true;
            this.label8.Location = new Point(0x27, 0x17);
            this.label8.Name = "label8";
            this.label8.Size = new Size(0x1d, 12);
            this.label8.TabIndex = 10;
            this.label8.Text = "姓名";
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            base.ClientSize = new Size(0x2e1, 0x170);
            base.Controls.Add(this.groupBox1);
            base.Controls.Add(this.lbTitle);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnSave);
            base.Controls.Add(this.groupBox2);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FrmUpdateRegist";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "更新人员编制信息";
            base.Load += new EventHandler(this.FrmUpdateBaseInfo_Load);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void UserInfoBind()
        {
            this.model = this.userbll.GetModel(this.userID);
            if (this.model != null)
            {
                this.UserName.Text = this.model.UserName;
                this.txtID.Text = this.model.ID;
                this.RegistDay.Value = !this.model.RegistDay.HasValue ? DateTime.Now : this.model.RegistDay.Value;
                this.RegistDate.Value = !this.model.RegistDate.HasValue ? DateTime.Now : this.model.RegistDate.Value;
                this.RegistWay.Text = this.model.RegistWay;
                this.RegistFrom.Text = this.model.RegistFrom;
                this.RegistTo.Text = this.model.RegistTo;
                if (this.model.OrganID.HasValue)
                {
                    this.RegistTo.Tag = new OrganBLL().GetModel(this.model.OrganID.Value);
                }
                this.RegistNo.Text = this.model.RegistNo;
                this.RegistSummary.Text = this.model.RegistSummary;
                this.RegistState.Text = this.model.RegistState;
                this.RegistType.Text = this.model.RegistType;
                this.IsHighWith.Checked = this.model.IsHeighWith == 1;
            }
            else
            {
                MessageBox.Show("用户不存在！");
                base.Close();
            }
        }

        private void UserRegistStateBind()
        {
            List<UserRegistState> list = new UserRegistStateBLL().GetList();
            UserRegistState item = new UserRegistState {
                StateName = "请选择",
                StateID = 0
            };
            list.Insert(0, item);
            this.RegistState.DisplayMember = "StateName";
            this.RegistState.ValueMember = "StateID";
            this.RegistState.DataSource = list;
        }

        private void UserRegistWayBind()
        {
            List<UserRegistWay> list = new UserRegistWayBLL().GetList();
            list = (list == null) ? new List<UserRegistWay>() : list;
            UserRegistWay item = new UserRegistWay {
                WayName = "请选择",
                WayID = 0
            };
            list.Insert(0, item);
            this.RegistWay.DisplayMember = "WayName";
            this.RegistWay.ValueMember = "WayID";
            this.RegistWay.DataSource = list;
        }
    }
}

